package com.siao.display
{
	import com.siao.errors.ElementError;
	
	import flash.accessibility.AccessibilityImplementation;
	import flash.accessibility.AccessibilityProperties;
	import flash.display.BlendMode;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Graphics;
	import flash.display.InteractiveObject;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.geom.Transform;
	import flash.geom.Vector3D;
	import flash.media.SoundTransform;
	import flash.text.TextSnapshot;
	
	/**
	 * 单一内容的显示元素，该元素只有一个子元素content
	 * @author SiaoLeon
	 */
	public class SingleElement extends TooltipElement
	{
		// -------------------------------------------------------------------------------------------------------- 静态常量
		
		// -------------------------------------------------------------------------------------------------------- 静态变量
		
		// -------------------------------------------------------------------------------------------------------- 静态方法
		
		// -------------------------------------------------------------------------------------------------------- 静态函数
		
		// -------------------------------------------------------------------------------------------------------- 属性
		
		private var _accessibilityImplementation:AccessibilityImplementation = super.accessibilityImplementation;
		
		override public function get accessibilityImplementation():AccessibilityImplementation
		{
			return (this.content == null || !(this.content is InteractiveObject)) ? this._accessibilityImplementation : (this.content as InteractiveObject).accessibilityImplementation;
		}
		
		override public function set accessibilityImplementation(value:AccessibilityImplementation):void
		{
			this._accessibilityImplementation = value;
			
			if (this.content != null && this.content is InteractiveObject)
			{
				(this.content as InteractiveObject).accessibilityImplementation = value;
			}
		}
		
		private var _accessibilityProperties:AccessibilityProperties = super.accessibilityProperties;
		
		override public function get accessibilityProperties():AccessibilityProperties
		{
			return (this.content == null) ? this._accessibilityProperties : this.content.accessibilityProperties;
		}
		
		override public function set accessibilityProperties(value:AccessibilityProperties):void
		{
			this._accessibilityProperties = value;
			
			if (this.content != null)
			{
				this.content.accessibilityProperties = value;
			}
		}
		
		private var _alpha:Number = super.alpha;
		
		override public function get alpha():Number
		{
			return (this.content == null) ? this._alpha : this.content.alpha;
		}
		
		override public function set alpha(value:Number):void
		{
			this._alpha = value;
			
			if (this.content != null)
			{
				this.content.alpha = value;
			}
		}
		
		private var _blendMode:String = super.blendMode;
		
		override public function get blendMode():String
		{
			return (this.content == null) ? this._blendMode : this.content.blendMode;
		}
		
		override public function set blendMode(value:String):void
		{
			this._blendMode = value;
			
			if (this.content != null)
			{
				this.content.blendMode = value;
			}
		}
		
		private var _buttonMode:Boolean = super.buttonMode;
		
		override public function get buttonMode():Boolean
		{
			return (this.content == null || !(this.content is Sprite)) ? this._buttonMode : (this.content as Sprite).buttonMode;
		}
		
		override public function set buttonMode(value:Boolean):void
		{
			super.buttonMode = this._buttonMode = value;
			
			if (this.content != null && this.content is Sprite)
			{
				(this.content as Sprite).buttonMode = value;
			}
		}
		
		private var _cacheAsBitmap:Boolean = super.cacheAsBitmap;
		
		override public function get cacheAsBitmap():Boolean
		{
			return (this.content == null) ? this._cacheAsBitmap : this.content.cacheAsBitmap;
		}
		
		override public function set cacheAsBitmap(value:Boolean):void
		{
			this._cacheAsBitmap = value;
			
			if (this.content != null)
			{
				this.content.cacheAsBitmap = value;
			}
		}
		
		//		private var _contextMenu:ContextMenu = super.contextMenu;
		//		
		//		override public function get contextMenu():ContextMenu
		//		{
		//			return (this.content == null || !(this.content is InteractiveObject)) ? this._contextMenu : (this.content as InteractiveObject).contextMenu;
		//		}
		//		
		//		override public function set contextMenu(cm:ContextMenu):void
		//		{
		//			this._contextMenu = cm;
		//			
		//			if (this.content != null && this.content is InteractiveObject)
		//			{
		//				(this.content as InteractiveObject).contextMenu = cm;
		//			}
		//		}
		
		private var _doubleClickEnabled:Boolean = super.doubleClickEnabled
		
		override public function get doubleClickEnabled():Boolean
		{
			return (this.content == null || !(this.content is InteractiveObject)) ? this._doubleClickEnabled : (this.content as InteractiveObject).doubleClickEnabled;
		}
		
		override public function set doubleClickEnabled(enabled:Boolean):void
		{
			this._doubleClickEnabled = enabled;
			
			if (this.content != null && this.content is InteractiveObject)
			{
				(this.content as InteractiveObject).doubleClickEnabled = enabled;
			}
		}
		
		override public function get dropTarget():DisplayObject
		{
			return (this.content == null || !(this.content is Sprite)) ? super.dropTarget : (this.content as Sprite).dropTarget;
		}
		
		private var _filters:Array = super.filters;
		
		override public function get filters():Array
		{
			return (this.content == null) ? this._filters : this.content.filters;
		}
		
		override public function set filters(value:Array):void
		{
			this._filters = value;
			
			if (this.content != null)
			{
				this.content.filters = value;
			}
		}
		
		private var _focusRect:Object = super.focusRect;
		
		override public function get focusRect():Object
		{
			return (this.content == null || !(this.content is InteractiveObject)) ? this._focusRect : (this.content as InteractiveObject).focusRect;
		}
		
		override public function set focusRect(focusRect:Object):void
		{
			this._focusRect = focusRect;
			
			if (this.content != null && this.content is InteractiveObject)
			{
				(this.content as InteractiveObject).focusRect = focusRect;
			}
		}
		
		override public function get graphics():Graphics
		{
			return (this.content == null || !(this.content is Sprite)) ? super.graphics : (this.content as Sprite).graphics;
		}
		
		private var _hitArea:Sprite = super.hitArea;
		
		override public function get hitArea():Sprite
		{
			return (this.content == null || !(this.content is Sprite)) ? this._hitArea : (this.content as Sprite).hitArea;
		}
		
		override public function set hitArea(value:Sprite):void
		{
			this._hitArea = value;
			
			if (this.content != null && this.content is Sprite)
			{
				(this.content as Sprite).hitArea = value;
			}
		}
		
		private var _mask:DisplayObject = super.mask;
		
		override public function get mask():DisplayObject
		{
			return (this.content == null) ? this._mask : this.content.mask;
		}
		
		override public function set mask(value:DisplayObject):void
		{
			this._mask = value;
			
			if (this.content != null && this.content is Sprite)
			{
				(this.content as Sprite).mask = value;
			}
		}
		
		override public function get loaderInfo():LoaderInfo
		{
			return (this.content == null) ? super.loaderInfo : this.content.loaderInfo;
		}
		
		private var _mouseChildren:Boolean = super.mouseChildren;
		
		override public function get mouseChildren():Boolean
		{
			return (this.content == null || !(this.content is DisplayObjectContainer)) ? this._mouseChildren : (this.content as DisplayObjectContainer).mouseChildren;
		}
		
		override public function set mouseChildren(enable:Boolean):void
		{
			super.mouseChildren = this._mouseChildren = enable;
			
			if (this.content != null && this.content is DisplayObjectContainer)
			{
				(this.content as DisplayObjectContainer).mouseChildren = enable;
			}
		}
		
		private var _mouseEnabled:Boolean = super.mouseEnabled;
		
		override public function get mouseEnabled():Boolean
		{
			return (this.content == null || !(this.content is InteractiveObject)) ? this._mouseEnabled : (this.content as InteractiveObject).mouseEnabled;
		}
		
		override public function set mouseEnabled(enabled:Boolean):void
		{
			super.mouseEnabled = this._mouseEnabled = enabled;
			
			if (this.content != null && this.content is InteractiveObject)
			{
				(this.content as InteractiveObject).mouseEnabled = enabled;
			}
		}
		
		override public function get mouseX():Number
		{
			return (this.content == null) ? super.mouseX : this.content.mouseX;
		}
		
		override public function get mouseY():Number
		{
			return (this.content == null) ? super.mouseY : this.content.mouseY;
		}
		
		private var _name:String = super.name;
		
		override public function get name():String
		{
			return (this.content == null) ? this._name : this.content.name;
		}
		
		override public function set name(value:String):void
		{
			this._name = value;
			
			if (this.content != null)
			{
				try
				{
					this.content.name = value;
				}
				catch (err:Error)
				{
					
				}
			}
		}
		
		//		private var _needsSoftKeyboard:Boolean = super.needsSoftKeyboard;
		//		
		//		override public function get needsSoftKeyboard():Boolean
		//		{
		//			return (this.content == null || !(this.content is InteractiveObject)) ? this._needsSoftKeyboard : (this.content as InteractiveObject).needsSoftKeyboard;
		//		}
		//		
		//		override public function set needsSoftKeyboard(value:Boolean):void
		//		{
		//			this._needsSoftKeyboard = value;
		//			
		//			if (this.content != null && this.content is InteractiveObject)
		//			{
		//				(this.content as InteractiveObject).needsSoftKeyboard = value;
		//			}
		//		}
		
		override public function get numChildren():int
		{
			return (this.content == null || !(this.content is DisplayObjectContainer)) ? super.numChildren : (this.content as DisplayObjectContainer).numChildren;
		}
		
		private var _opaqueBackground:Object = super.opaqueBackground;
		
		override public function get opaqueBackground():Object
		{
			return (this.content == null) ? this._opaqueBackground : this.content.opaqueBackground;
		}
		
		override public function set opaqueBackground(value:Object):void
		{
			this._opaqueBackground = value;
			
			if (this.content != null)
			{
				this.content.opaqueBackground = value;
			}
		}
		
		override public function get parent():DisplayObjectContainer
		{
			return super.parent;
		}
		
		override public function get root():DisplayObject
		{
			return (this.content == null) ? super.root : this.content.root;
		}
		
		private var _rotation:Number = super.rotation;
		
		override public function get rotation():Number
		{
			return (this.content == null) ? this._rotation : this.content.rotation;
		}
		
		override public function set rotation(value:Number):void
		{
			this._rotation = value;
			
			if (this.content != null)
			{
				this.content.rotation = value;
			}
		}
		
		private var _rotationX:Number = super.rotationX;
		
		override public function get rotationX():Number
		{
			return (this.content == null) ? this._rotationX : this.content.rotationX;
		}
		
		override public function set rotationX(value:Number):void
		{
			this._rotationX = value;
			
			if (this.content != null)
			{
				this.content.rotationX = value;
			}
		}
		
		private var _rotationY:Number = super.rotationY;
		
		override public function get rotationY():Number
		{
			return (this.content == null) ? this._rotationY : this.content.rotationY;
		}
		
		override public function set rotationY(value:Number):void
		{
			this._rotationY = value;
			
			if (this.content != null)
			{
				this.content.rotationY = value;
			}
		}
		
		private var _rotationZ:Number = super.rotationZ;
		
		override public function get rotationZ():Number
		{
			return (this.content == null) ? this._rotationZ : this.content.rotationZ;
		}
		
		override public function set rotationZ(value:Number):void
		{
			this._rotationZ = value;
			
			if (this.content != null)
			{
				this.content.rotationZ = value;
			}
		}
		
		private var _scale9Grid:Rectangle = super.scale9Grid;
		
		override public function get scale9Grid():Rectangle
		{
			return (this.content == null) ? this._scale9Grid : this.content.scale9Grid;
		}
		
		override public function set scale9Grid(innerRectangle:Rectangle):void
		{
			this._scale9Grid = innerRectangle;
			
			if (this.content != null)
			{
				this.content.scale9Grid = innerRectangle;
			}
		}
		
		private var _scaleX:Number = super.scaleX;
		
		override public function get scaleX():Number
		{
			return (this.content == null) ? this._scaleX : this.content.scaleX;
		}
		
		override public function set scaleX(value:Number):void
		{
			this._scaleX = value;
			
			if (this.content != null)
			{
				this.content.scaleX = value;
			}
		}
		
		private var _scaleY:Number = super.scaleY;
		
		override public function get scaleY():Number
		{
			return (this.content == null) ? this._scaleY : this.content.scaleY;
		}
		
		override public function set scaleY(value:Number):void
		{
			this._scaleY = value;
			
			if (this.content != null)
			{
				this.content.scaleY = value;
			}
		}
		
		private var _scaleZ:Number = super.scaleZ;
		
		override public function get scaleZ():Number
		{
			return (this.content == null) ? this._scaleZ : this.content.scaleZ;
		}
		
		override public function set scaleZ(value:Number):void
		{
			this._scaleZ = value;
			
			if (this.content != null)
			{
				this.content.scaleZ = value;
			}
		}
		
		private var _scrollRect:Rectangle = super.scrollRect;
		
		override public function get scrollRect():Rectangle
		{
			return (this.content == null) ? this._scrollRect : this.content.scrollRect;
		}
		
		override public function set scrollRect(value:Rectangle):void
		{
			this._scrollRect = value;
			
			if (this.content != null)
			{
				this.content.scrollRect = value;
			}
		}
		
		//		private var _softKeyboardInputAreaOfInterest:Rectangle = super.softKeyboardInputAreaOfInterest;
		//		
		//		override public function get softKeyboardInputAreaOfInterest():Rectangle
		//		{
		//			return (this.content == null || !(this.content is InteractiveObject)) ? this._softKeyboardInputAreaOfInterest : (this.content as InteractiveObject).softKeyboardInputAreaOfInterest;
		//		}
		//		
		//		override public function set softKeyboardInputAreaOfInterest(value:Rectangle):void
		//		{
		//			this._softKeyboardInputAreaOfInterest = value;
		//			
		//			if (this.content != null && this.content is InteractiveObject)
		//			{
		//				(this.content as InteractiveObject).softKeyboardInputAreaOfInterest = value;
		//			}
		//		}
		
		private var _soundTransform:SoundTransform = super.soundTransform;
		
		override public function get soundTransform():SoundTransform
		{
			return (this.content == null || !(this.content is Sprite)) ? this._soundTransform : (this.content as Sprite).soundTransform;
		}
		
		override public function set soundTransform(sndTransform:SoundTransform):void
		{
			this._soundTransform = sndTransform;
			
			if (this.content != null && this.content is Sprite)
			{
				(this.content as Sprite).soundTransform = sndTransform;
			}
		}
		
		override public function get stage():Stage
		{
			return super.stage;
		}
		
		private var _tabChildren:Boolean = super.tabChildren;
		
		override public function get tabChildren():Boolean
		{
			return (this.content == null || !(this.content is DisplayObjectContainer)) ? this._tabChildren : (this.content as DisplayObjectContainer).tabChildren;
		}
		
		override public function set tabChildren(enable:Boolean):void
		{
			this._tabChildren = enable;
			
			if (this.content != null && this.content is DisplayObjectContainer)
			{
				(this.content as DisplayObjectContainer).tabChildren = enable;
			}
		}
		
		private var _tabEnabled:Boolean = super.tabEnabled;
		
		override public function get tabEnabled():Boolean
		{
			return (this.content == null || !(this.content is InteractiveObject)) ? this._tabEnabled : (this.content as InteractiveObject).tabEnabled;
		}
		
		override public function set tabEnabled(enabled:Boolean):void
		{
			this._tabEnabled = enabled;
			
			if (this.content != null && this.content is InteractiveObject)
			{
				(this.content as InteractiveObject).tabEnabled = enabled;
			}
		}
		
		private var _tabIndex:int = super.tabIndex;
		
		override public function get tabIndex():int
		{
			return (this.content == null || !(this.content is InteractiveObject)) ? this._tabIndex : (this.content as InteractiveObject).tabIndex;
		}
		
		override public function set tabIndex(index:int):void
		{
			this._tabIndex = index;
			
			if (this.content != null && this.content is InteractiveObject)
			{
				(this.content as InteractiveObject).tabIndex = index;
			}
		}
		
		override public function get textSnapshot():TextSnapshot
		{
			return (this.content == null || !(this.content is DisplayObjectContainer)) ? super.textSnapshot : (this.content as DisplayObjectContainer).textSnapshot;
		}
		
		private var _transform:Transform = super.transform;
		
		override public function get transform():Transform
		{
			return (this.content == null) ? this._transform : this.content.transform;
		}
		
		override public function set transform(value:Transform):void
		{
			this._transform = value;
			
			if (this.content != null)
			{
				this.content.transform = value;
			}
		}
		
		private var _useHandCursor:Boolean = super.useHandCursor;
		
		override public function get useHandCursor():Boolean
		{
			return (this.content == null || !(this.content is Sprite)) ? this._useHandCursor : (this.content as Sprite).useHandCursor;
		}
		
		override public function set useHandCursor(value:Boolean):void
		{
			this._useHandCursor = value;
			
			if (this.content != null && this.content is Sprite)
			{
				(this.content as Sprite).useHandCursor = value;
			}
		}
		
		private var _visible:Boolean = super.visible;
		
		override public function get visible():Boolean
		{
			return (this.content == null) ? this._visible : this.content.visible;
		}
		
		override public function set visible(value:Boolean):void
		{
			if (value == this.visible)
			{
				return;
			}
			
			if (this.content != null)
			{
				this.content.visible = value;
			}
			
			super.visible = value;
			this._visible = value;
		}
		
		private var _width:Number;
		
		override public function get width():Number
		{
			return (this.content == null) ? 0 : this.content.width;
		}
		
		override public function set width(value:Number):void
		{
			this._width = value;
			
			if (this.content != null)
			{
				this.content.width = value;
			}
			
			super.width = value;
		}
		
		private var _height:Number;
		
		override public function get height():Number
		{
			return (this.content == null) ? 0 : this.content.height;
		}
		
		override public function set height(value:Number):void
		{
			this._height = value;
			
			if (this.content != null)
			{
				this.content.height = value;
			}
			
			super.height = value;
		}
		
		private var _x:Number = super.x;
		
		override public function get x():Number
		{
			return (this.content == null) ? this._x : this.content.x;
		}
		
		override public function set x(value:Number):void
		{
			this._x = value;
			
			if (this.content != null)
			{
				this.content.x = value;
			}
		}
		
		private var _y:Number = super.y;
		
		override public function get y():Number
		{
			return (this.content == null) ? this._y : this.content.y;
		}
		
		override public function set y(value:Number):void
		{
			this._y = value;
			
			if (this.content != null)
			{
				this.content.y = value;
			}
		}
		
		private var _z:Number = super.z;
		
		override public function get z():Number
		{
			return (this.content == null) ? this._z : this.content.z;
		}
		
		override public function set z(value:Number):void
		{
			this._z = value;
			
			if (this.content != null)
			{
				this.content.z = value;
			}
		}
		
		protected var _content:DisplayObject;
		
		/**
		 * 显示内容对象
		 * @return
		 */
		public function get content():DisplayObject
		{
			return this._content;
		}
		
		public function set content(value:DisplayObject):void
		{
			//移除当前内容对象
			if (this.content != null && super.contains(this.content))
			{
				super.removeChild(this.content);
			}
			
			//设置当前内容对象
			this._content = value;
			
			if (this.content == null)
			{
				return;
			}
			
			//配置当前内容对象属性（优先级：元素属性->内容对象属性->默认）
			if (this._accessibilityImplementation != null)
			{
				this.content.accessibilityProperties = this._accessibilityProperties;
			}
			
			if (this._alpha != 1)
			{
				this.content.alpha = this._alpha;
			}
			
			if (this._blendMode != BlendMode.NORMAL)
			{
				this.content.blendMode = this._blendMode;
			}
			
			if (this._cacheAsBitmap != false)
			{
				this.content.cacheAsBitmap = this._cacheAsBitmap;
			}
			
			if (this._filters.length != 0)
			{
				this.content.filters = this._filters;
			}
			
			if (this._opaqueBackground != null)
			{
				this.content.opaqueBackground = this._opaqueBackground;
			}
			
			if (this._rotation != 0)
			{
				this.content.rotation = this._rotation;
			}
			
			if (this._rotationX != 0)
			{
				this.content.rotationX = this._rotationX;
			}
			
			if (this._rotationY != 0)
			{
				this.content.rotationY = this._rotationY;
			}
			
			if (this._rotationZ != 0)
			{
				this.content.rotationZ = this._rotationZ;
			}
			
			if (this._scale9Grid != null)
			{
				this.content.scale9Grid = this._scale9Grid;
			}
			
			if (this._scaleX != 1)
			{
				this.content.scaleX = this._scaleX;
			}
			
			if (this._scaleY != 1)
			{
				this.content.scaleY = this._scaleY;
			}
			
			if (this._scaleZ != 1)
			{
				this.content.scaleZ = this._scaleZ;
			}
			
			if (this._scrollRect != null)
			{
				this.content.scrollRect = this._scrollRect;
			}
			
			if (this._visible != true)
			{
				this.content.visible = this._visible;
			}
			
			if (this._x != 0)
			{
				this.content.x = this._x;
			}
			
			if (this._y != 0)
			{
				this.content.y = this._y;
			}
			
			if (this._z != 0)
			{
				this.content.z = this._z;
			}
			
			if (this._mask != null)
			{
				this.content.mask = this._mask;
			}
			
			if (!isNaN(this._width))
			{
				this.content.width = this._width;
			}
			
			if (!isNaN(this._height))
			{
				this.content.height = this._height;
			}
			
			if (this._name != null)
			{
				try
				{
					this.content.name = this._name;
				}
				catch (err:Error)
				{
					
				}
			}
			
			if (this.content is InteractiveObject)
			{
				if (this._accessibilityProperties != null)
				{
					(this.content as InteractiveObject).accessibilityImplementation = this._accessibilityImplementation;
				}
				
				//				if (this._contextMenu != null)
				//				{
				//					(this.content as InteractiveObject).contextMenu = this._contextMenu;
				//				}
				
				if (this._doubleClickEnabled != false)
				{
					(this.content as InteractiveObject).doubleClickEnabled = this._doubleClickEnabled;
				}
				
				if (this._focusRect != null)
				{
					(this.content as InteractiveObject).focusRect = this._focusRect;
				}
				
				if (this._mouseEnabled != true)
				{
					(this.content as InteractiveObject).mouseEnabled = this._mouseEnabled;
				}
				
				//				if (this._needsSoftKeyboard != false)
				//				{
				//					(this.content as InteractiveObject).needsSoftKeyboard = this._needsSoftKeyboard;
				//				}
				//				
				//				if (this._softKeyboardInputAreaOfInterest != null)
				//				{
				//					(this.content as InteractiveObject).softKeyboardInputAreaOfInterest = this._softKeyboardInputAreaOfInterest;
				//				}
				
				if (this._tabEnabled != false)
				{
					(this.content as InteractiveObject).tabEnabled = this._tabEnabled;
				}
				
				if (this._tabIndex != -1)
				{
					(this.content as InteractiveObject).tabIndex = this._tabIndex;
				}
			}
			
			if (this.content is DisplayObjectContainer)
			{
				if (this._mouseChildren != true)
				{
					(this.content as DisplayObjectContainer).mouseChildren = this._mouseChildren;
				}
				
				if (this._tabChildren != true)
				{
					(this.content as DisplayObjectContainer).tabChildren = this._tabChildren;
				}
			}
			
			if (this.content is Sprite)
			{
				if (this._buttonMode != false)
				{
					(this.content as Sprite).buttonMode = this._buttonMode;
				}
				
				if (this._hitArea != null)
				{
					(this.content as Sprite).hitArea = this._hitArea;
				}
				
				if (this._useHandCursor != true)
				{
					(this.content as Sprite).useHandCursor = this._useHandCursor;
				}
				
				if (this._soundTransform.leftToLeft != 1 || this._soundTransform.leftToRight != 0 || this._soundTransform.pan != 0 || this._soundTransform.rightToLeft != 0 || this._soundTransform.rightToRight != 1 || this._soundTransform.volume != 1)
				{
					(this.content as Sprite).soundTransform = this._soundTransform;
				}
			}
			
			this.position();
			
			super.addChild(this._content);
		}
		
		// -------------------------------------------------------------------------------------------------------- 变量
		
		// -------------------------------------------------------------------------------------------------------- 构造
		
		/**
		 * 构造函数
		 * @param content 显示内容对象
		 */
		public function SingleElement(content:DisplayObject=null)
		{
			super();
			
			this._content = (content == null) ? new Sprite() : content;
			
			super.tabEnabled = super.focusRect = false;
			super.tabIndex = -1;
			super.addChild(this._content);
		}
		
		// -------------------------------------------------------------------------------------------------------- 方法
		
		override public function addChild(child:DisplayObject):DisplayObject
		{
			if (this.content == null)
			{
				this.content = child;
				return child;
			}
			
			if (!(this.content is DisplayObjectContainer))
			{
				throw new ElementError(this, "的显示内容不是有效的显示容器，无法添加子级显示对象。")
			}
			
			return (this.content as DisplayObjectContainer).addChild(child);
		}
		
		override public function addChildAt(child:DisplayObject, index:int):DisplayObject
		{
			if (this.content == null)
			{
				this.content = child;
				return child;
			}
			
			if (!(this.content is DisplayObjectContainer))
			{
				throw new ElementError(this, "的显示内容不是有效的显示容器，无法添加子级显示对象。")
			}
			
			return (this.content as DisplayObjectContainer).addChildAt(child, index);
		}
		
		override public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
		{
			super.addEventListener(type, listener, useCapture, priority, useWeakReference);
		}
		
		override public function areInaccessibleObjectsUnderPoint(point:Point):Boolean
		{
			if (this.content == null || !(this.content is DisplayObjectContainer))
			{
				return super.areInaccessibleObjectsUnderPoint(point);
			}
			
			return (this.content as DisplayObjectContainer).areInaccessibleObjectsUnderPoint(point);
		}
		
		override public function contains(child:DisplayObject):Boolean
		{
			if (this.content == null || !(this.content is DisplayObjectContainer))
			{
				return false;
			}
			
			return (this.content as DisplayObjectContainer).contains(child);
		}
		
		override public function dispatchEvent(event:Event):Boolean
		{
			return super.dispatchEvent(event);
		}
		
		override public function getBounds(targetCoordinateSpace:DisplayObject):Rectangle
		{
			return (this.content == null) ? super.getBounds(targetCoordinateSpace) : this.content.getBounds(targetCoordinateSpace);
		}
		
		override public function getChildAt(index:int):DisplayObject
		{
			if (this.content == null || !(this.content is DisplayObjectContainer))
			{
				return super.getChildAt(index);
			}
			
			return (this.content as DisplayObjectContainer).getChildAt(index);
		}
		
		override public function getChildByName(name:String):DisplayObject
		{
			if (this.content == null || !(this.content is DisplayObjectContainer))
			{
				return super.getChildByName(name);
			}
			
			return (this.content as DisplayObjectContainer).getChildByName(name);
		}
		
		override public function getChildIndex(child:DisplayObject):int
		{
			if (this.content == null || !(this.content is DisplayObjectContainer))
			{
				return super.getChildIndex(child);
			}
			
			return (this.content as DisplayObjectContainer).getChildIndex(child);
		}
		
		override public function getObjectsUnderPoint(point:Point):Array
		{
			if (this.content == null || !(this.content is DisplayObjectContainer))
			{
				return super.getObjectsUnderPoint(point);
			}
			
			return (this.content as DisplayObjectContainer).getObjectsUnderPoint(point);
		}
		
		override public function getRect(targetCoordinateSpace:DisplayObject):Rectangle
		{
			return (this.content == null) ? super.getRect(targetCoordinateSpace) : this.content.getRect(targetCoordinateSpace);
		}
		
		override public function globalToLocal(point:Point):Point
		{
			return (this.content == null) ? super.globalToLocal(point) : this.content.globalToLocal(point);
		}
		
		override public function globalToLocal3D(point:Point):Vector3D
		{
			return (this.content == null) ? super.globalToLocal3D(point) : this.content.globalToLocal3D(point);
		}
		
		override public function hasEventListener(type:String):Boolean
		{
			return super.hasEventListener(type);
		}
		
		override public function hitTestObject(obj:DisplayObject):Boolean
		{
			return (this.content == null) ? super.hitTestObject(obj) : this.content.hitTestObject(obj);
		}
		
		override public function hitTestPoint(x:Number, y:Number, shapeFlag:Boolean=false):Boolean
		{
			return (this.content == null) ? super.hitTestPoint(x, y, shapeFlag) : this.content.hitTestPoint(x, y, shapeFlag);
		}
		
		override public function local3DToGlobal(point3d:Vector3D):Point
		{
			return (this.content == null) ? super.local3DToGlobal(point3d) : this.content.local3DToGlobal(point3d);
		}
		
		override public function localToGlobal(point:Point):Point
		{
			return (this.content == null) ? super.localToGlobal(point) : this.content.localToGlobal(point);
		}
		
		override public function removeChild(child:DisplayObject):DisplayObject
		{
			if (this.content == null)
			{
				return super.removeChild(child);
			}
			
			if (this.content == child)
			{
				this.content = null;
				return child;
			}
			
			if (!(this.content is DisplayObjectContainer))
			{
				throw new ElementError(this, "的显示内容不是有效的显示容器，无法移除子级显示对象。")
			}
			
			return (this.content as DisplayObjectContainer).removeChild(child);
		}
		
		override public function removeChildAt(index:int):DisplayObject
		{
			if (this.content == null)
			{
				return super.removeChildAt(index);
			}
			
			if (!(this.content is DisplayObjectContainer))
			{
				throw new ElementError(this, "的显示内容不是有效的显示容器，无法移除子级显示对象。")
			}
			
			return (this.content as DisplayObjectContainer).removeChildAt(index);
		}
		
		//		override public function removeChildren(beginIndex:int=0, endIndex:int=2147483647):void
		//		{
		//			if (this.content == null)
		//			{
		//				super.removeChildren(beginIndex, endIndex);
		//				return;
		//			}
		//			
		//			if (!(this.content is DisplayObjectContainer))
		//			{
		//				throw new ElementError(this, "的显示内容不是有效的显示容器，无法移除子级显示对象。")
		//			}
		//			
		//			(this.content as DisplayObjectContainer).removeChildren();
		//		}
		
		override public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void
		{
			super.removeEventListener(type, listener, useCapture);
		}
		
		//		override public function requestSoftKeyboard():Boolean
		//		{
		//			if (this.content == null || !(this.content is InteractiveObject))
		//			{
		//				return super.requestSoftKeyboard();
		//			}
		//			
		//			return (this.content as InteractiveObject).requestSoftKeyboard();
		//		}
		
		override public function setChildIndex(child:DisplayObject, index:int):void
		{
			if (this.content == null || !(this.content is DisplayObjectContainer))
			{
				super.setChildIndex(child, index);
				return;
			}
			
			(this.content as DisplayObjectContainer).setChildIndex(child, index);
		}
		
		override public function startDrag(lockCenter:Boolean=false, bounds:Rectangle=null):void
		{
			if (this.content == null || !(this.content is Sprite))
			{
				super.startDrag(lockCenter, bounds);
				return;
			}
			
			(this.content as Sprite).startDrag(lockCenter, bounds);
		}
		
		override public function startTouchDrag(touchPointID:int, lockCenter:Boolean=false, bounds:Rectangle=null):void
		{
			if (this.content == null || !(this.content is Sprite))
			{
				super.startTouchDrag(touchPointID, lockCenter, bounds);
				return;
			}
			
			(this.content as Sprite).startTouchDrag(touchPointID, lockCenter, bounds);
		}
		
		override public function stopDrag():void
		{
			if (this.content == null || !(this.content is Sprite))
			{
				super.stopDrag();
				return;
			}
			
			(this.content as Sprite).stopDrag();
		}
		
		override public function stopTouchDrag(touchPointID:int):void
		{
			if (this.content == null || !(this.content is Sprite))
			{
				super.stopTouchDrag(touchPointID);
				return;
			}
			
			(this.content as Sprite).stopTouchDrag(touchPointID);
		}
		
		override public function swapChildren(child1:DisplayObject, child2:DisplayObject):void
		{
			if (this.content == null || !(this.content is DisplayObjectContainer))
			{
				super.swapChildren(child1, child2);
				return;
			}
			
			(this.content as DisplayObjectContainer).swapChildren(child1, child2);
		}
		
		override public function swapChildrenAt(index1:int, index2:int):void
		{
			if (this.content == null || !(this.content is DisplayObjectContainer))
			{
				super.swapChildren(index1, index2);
				return;
			}
			
			(this.content as DisplayObjectContainer).swapChildrenAt(index1, index2);
		}
		
		override public function toString():String
		{
			return (this.content == null) ? super.toString() : this.content.toString();
		}
		
		override public function willTrigger(type:String):Boolean
		{
			return (this.content == null) ? super.willTrigger(type) : this.content.willTrigger(type);
		}
	
		// -------------------------------------------------------------------------------------------------------- 函数
	
	}
}
